package com.zy.system.service.impl;

import java.util.List;

import com.zy.common.annotation.DataScope;
import com.zy.common.constant.UserConstants;
import com.zy.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.zy.system.mapper.SysUserMapper;
import com.zy.system.domain.SysUser;
import com.zy.system.service.ISysUserService;
import com.zy.common.support.Convert;

/**
 * 用户 服务层实现
 *
 * @author zy
 * @date 2018-12-19
 */
@Service
public class SysUserServiceImpl implements ISysUserService
{
    @Autowired
    private SysUserMapper userMapper;

    /**
     * 查询用户信息
     *
     * @param userId 用户ID
     * @return 用户信息
     */
    @Override
    public SysUser selectSysUserById(Integer userId)
    {
        return userMapper.selectSysUserById(userId);
    }

    /**
     * 查询用户列表
     *
     * @param sysUser 用户信息
     * @return 用户集合
     */
    @Override
    public List<SysUser> selectSysUserList(SysUser sysUser)
    {
        return userMapper.selectSysUserList(sysUser);
    }

    /**
     * 新增用户
     *
     * @param sysUser 用户信息
     * @return 结果
     */
    @Override
    public int insertSysUser(SysUser sysUser)
    {
        return userMapper.insertSysUser(sysUser);
    }

    /**
     * 修改用户
     *
     * @param sysUser 用户信息
     * @return 结果
     */
    @Override
    public int updateSysUser(SysUser sysUser)
    {
        return userMapper.updateSysUser(sysUser);
    }

    /**
     * 删除用户对象
     *
     * @param ids 需要删除的数据ID
     * @return 结果
     */
    @Override
    public int deleteSysUserByIds(String ids)
    {
        return userMapper.deleteSysUserByIds(Convert.toStrArray(ids));
    }

    @Override
    public SysUser selectUserByLoginName(String userName)
    {
        return userMapper.selectUserByLoginName(userName);
    }

    @Override
    public SysUser selectUserByPhoneNumber(String phoneNumber)
    {
        return userMapper.selectUserByPhoneNumber(phoneNumber);
    }

    @Override
    public SysUser selectUserByEmail(String email)
    {
        return userMapper.selectUserByEmail(email);
    }

    @Override
    public int updateUserInfo(SysUser user)
    {
        return userMapper.updateUser(user);
    }

    @Override
    @DataScope(tableAlias = "u")
    public List<SysUser> selectUserList(SysUser user)
    {
        return userMapper.selectSysUserList(user);
    }

    @Override
    public String checkLoginNameUnique(String loginName)
    {
        int count = userMapper.checkLoginNameUnique(loginName);
        if (count > 0)
        {
            return UserConstants.USER_NAME_NOT_UNIQUE;
        }
        return UserConstants.USER_NAME_UNIQUE;
    }

    @Override
    public String checkPhoneUnique(SysUser user)
    {
        //1.判断userId
        //2.检验手机号码
        Long userId = StringUtils.isNull(user.getUserId()) ? -1L : user.getUserId();
        SysUser info = userMapper.checkPhoneUnique(user.getPhonenumber());
       if (StringUtils.isNotNull()){

       }
        return null;
    }

    @Override
    public String checkEmailUnique(SysUser user)
    {
        return null;
    }

}
